﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MetaTracker.ViewModel;
using System.Diagnostics;

namespace MetaTracker.View
{
    /// <summary>
    /// Interaction logic for WeightServiceView.xaml
    /// </summary>
    public partial class WeightServiceView : UserControl
    {
        public WeightServiceView()
        {
            InitializeComponent();

            if (DataContext == null || !(DataContext is WeightServiceViewModel))
            {
                DataContext = new WeightServiceViewModel();
            }
        }

        #region EventHandeling
        private void WeightServiceView_Loaded(object sender, RoutedEventArgs e)
        {
            if (DataContext != null && (DataContext is WeightServiceViewModel))
            {
                (DataContext as WeightServiceViewModel).InitializeData();
            }

            
        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
            e.Handled = true;
        }

        private void AutoGeneratedColumnRenamer(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            //http://mareinsula.wordpress.com/2011/06/06/tips-on-wpf-autogeneratinged-datagrid/


            if (e.PropertyType == typeof(DateTime) || e.PropertyType == typeof(DateTime?))
            {
                (e.Column as DataGridTextColumn).Binding.StringFormat = "MM/dd/yyyy";
            }
            else if (e.PropertyType == typeof(double) || e.PropertyType == typeof(double?))
            {
                (e.Column as DataGridTextColumn).Binding.StringFormat = "000.0";
            }
        }
        #endregion //EventHandeling

        
    }
}
